﻿using System;
using System.Xml;

namespace TTprotons.Crm.JavascriptAudit.Common
{
    public class ParameterXmlParser
    {
        public ParameterXmlParser(string parameterXml)
        {
            IsSuccess = false;
            Parse(parameterXml);
        }

        #region Properties

        public string EntityName
        { get; private set; }

        public bool IsSuccess
        { get; private set; }

        #endregion

        private void Parse(string parameterXml)
        {
            try
            {
                var xmlDocument = new XmlDocument();
                xmlDocument.LoadXml(parameterXml);

                // Get the /Publish/Entities/Entity node.
                var entityNode = xmlDocument.FirstChild.FirstChild.FirstChild;
                if (!entityNode.Name.Equals("entity"))
                    return;

                EntityName = entityNode.InnerText;
                IsSuccess = true;
            }
            catch (Exception)
            { }
        }
    }
}